// Package startup
// Created by GoLand
// @User: lenora
// @Date: 2023/12/24
// @Time: 14:17

//go:build wireinject

package startup

import (
	repository2 "camp/microbook/interactive/repository"
	cache2 "camp/microbook/interactive/repository/cache"
	dao2 "camp/microbook/interactive/repository/dao"
	service2 "camp/microbook/interactive/service"
	aevent "camp/microbook/internal/events/article"
	"camp/microbook/internal/job"
	"camp/microbook/internal/repository"
	"camp/microbook/internal/repository/cache"
	"camp/microbook/internal/repository/dao"
	"camp/microbook/internal/repository/dao/article"
	"camp/microbook/internal/service"
	"camp/microbook/internal/web"
	ijwt "camp/microbook/internal/web/jwt"
	"camp/microbook/ioc"
	"github.com/gin-gonic/gin"
	"github.com/google/wire"
)

var thirdPartySet = wire.NewSet(
	//第三方依赖
	InitDb, InitRedis, InitLogger)

var interactiveSvcSet = wire.NewSet(
	dao2.NewGORMInteractiveDAO,
	cache2.NewInteractiveRedisCache,
	repository2.NewInteractiveRepository,
	service2.NewInteractiveService,
)

var userSvcSet = wire.NewSet(
	dao.NewUserDAO,
	cache.NewUserCache,
	repository.NewUserRepository,
)

func InitWebServer() *gin.Engine {
	wire.Build(
		thirdPartySet,
		/*ioc.InitLimiter, /ioc.InitFailover, ioc.InitSmsAuth,

		sms.NewTopService,*/ioc.InitSmsService, ioc.InitWechat,

		article.NewGormArticleDao,
		//领域对象操作
		dao.NewUserDAO, cache.NewUserCache, cache.NewCodeCache,
		//repository
		repository.NewCodeRepository, repository.NewUserRepository,
		//svc
		service.NewCodeService, service.NewUserService,
		//handler
		web.NewCommonHandler, web.NewUserHandler, ijwt.NewRedisJWTHandler, web.NewWechatHandler, InitArticleHandler,
		//gin
		ioc.InitMiddlewares, ioc.InitWebServer,
	)
	return gin.Default()
}

func InitInteractiveService() service2.InteractiveService {
	wire.Build(thirdPartySet, interactiveSvcSet)
	return service2.NewInteractiveService(nil)
}

func InitArticleHandler(dao article.ArticleDao) *web.ArticleHandler {
	wire.Build(
		thirdPartySet,
		interactiveSvcSet,
		userSvcSet,
		InitSaramaClient,
		InitSyncProducer,
		cache.NewArticleRedisCache,
		repository.NewArticleRepository,
		service.NewArticleService,
		aevent.NewSaramaSyncProducer,
		web.NewArticleHandler)
	return &web.ArticleHandler{}
}

func InitSchedule() *job.Schedule {
	wire.Build(
		thirdPartySet,
		dao.NewGORMJobDAO,
		repository.NewPreemptJobRepository,
		service.NewCronJobService,
		job.NewSchedule,
	)
	return &job.Schedule{}
}
